
package com.sm.auth.service.impl;

import com.sm.auth.dto.LoginDto;
import com.sm.auth.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AuthServiceImpl implements AuthService {
    @Autowired
    private AuthenticationManager authenticationManager;
    @Override
    public String login(LoginDto loginDto) {
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginDto.getUsername(), loginDto.getPassword());
        Authentication authentication = authenticationManager.authenticate(authenticationToken);
        Object loginUser = authentication.getPrincipal();
        log.info("loginUser:{}", loginUser);
        //登录成功之后，返回token，此处的token后面需要使用jwt来进行生成
        return "asdasasdada-sadxcasdasda-asdasdsdas";
    }
}
